import re

# 读取navicat生成的整体建表语句文件，按照分隔符分割出每张表的每一个建表语句并按照表名写入不同的文件中
with open("./traffic_crm.sql", mode='r', encoding='utf8') as f:
    for table_create in "".join(f.readlines()).split("-- ----------------------------"):
        # 提取表名
        if table_create.strip() != "":
            table_name = re.search('TABLE `(.*)`  \(', table_create, re.S).group(1)
            with open(f"./mysql_ddl/{table_name}.sql",mode='w',encoding='utf8') as w:
                w.write(table_create.strip())